package com.qf.controller;

import com.qf.entity.TbStudent;
import com.qf.service.StudentService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author 王希卓
 * @Date 2023/7/15 16:52
 */
@RestController
public class StudentController {

    @Autowired
    private StudentService studentService;

    /**
     * 分页模糊查询所有学生
     * @param current 当前页码
     * @param size 每页显示条数
     * @param keyword 关键字
     * @return
     */
    @GetMapping("/student/findAll")
    public ResultMsg findAll(int current,int size,String keyword){
        return studentService.findAll(current,size,keyword==null?"":keyword);
    }

    /**
     * 添加或修改学生
     * @param tbStudent 学生实体
     * @return
     */
    @PostMapping("/student/update")
    public ResultMsg update(@RequestBody TbStudent tbStudent){
        return studentService.update(tbStudent);
    }

    /**
     * 根据学生id删除
     * @param studentId
     * @return
     */
    @GetMapping("/student/del")
    public ResultMsg del(int studentId){
        return studentService.del(studentId);
    }

    @PostMapping("student/login")
    public ResultMsg studentLogin(@RequestBody Map map, HttpServletRequest request){
        String name = (String) map.get("name");
        String password = (String) map.get("password");
        return studentService.studentlogin(name,password,request);
    }
}
